<?php
class FrontCategory
{
	public function getCategoryMenu()
	{
		$sql = "SELECT C.cat_id, C.cat_desc
				FROM tbl_category C
				WHERE C.status = 1 AND C.parent_id = 0 and C.cat_id<>50 ";
		
		$cat_arr = DB::fetchAll($sql);
		return $cat_arr;
	}
	
	public function getSubCatMenu()
	{
		$sql = "SELECT C1.cat_id AS CATID, C2.cat_id AS SUBCATID, C1.cat_desc AS PARENTCAT, C2.cat_desc AS SUBCAT, C1.status
				FROM tbl_category C1
				LEFT JOIN tbl_category C2 ON C1.parent_id = C2.cat_id
				WHERE C1.parent_id != 0";
		
		$sub_cat_arr = DB::fetchAll($sql);
		return $sub_cat_arr;
	}
	
	public function getCategories()
	{
		$sql = "SELECT cat_id, cat_desc
				FROM tbl_category
				WHERE STATUS = 1";
		
		$subcat_id_arr = DB::fetchAll($sql);
		return $subcat_id_arr;
	}

        public function getPowesearchfeatures($type,$val)
	{
                if($type=="cat")
                {
                  $cat=$val;
                }
                elseif($type=="subcat"){
                    $cat=$this->getcategorybysubcatid($val);
                }
		$sql = " select  distinct  structkey,{$cat} as catid  from tbl_tempstructuretable where catid=".$cat."";
		$feature_arr = DB::fetchAll($sql);
		return $feature_arr;
	}

         public function getcategorybysubcatid($subcatid)
	{
		$sql = "SELECT parent_id
				FROM tbl_category
				WHERE cat_id = " . $subcatid;
		$id = DB::fetchRow($sql);

		return $id["parent_id"];
	}
}
?>